<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form id="receiveRMPO" binding="#{rawMaterialPurchasingManagerBean.loadReceiveRMPO}">
                    <p:panel header="Raw Material Purchase Order" id="rmpoPanel">
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">Delivery Date:</td>
                                <td>
                                    <h:outputText value="#{rawMaterialPurchasingManagerBean.selectedRawMaterialPurchaseOrder.deliveryDate}" >
                                        <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{defaultManagerBean.tz}"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Purchasing Rep.:</td>
                                <td>
                                    <h:outputText value="#{rawMaterialPurchasingManagerBean.selectedRawMaterialPurchaseOrder.employee.name}" >
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Supplier:</td>
                                <td>
                                    <h:outputText value="#{rawMaterialPurchasingManagerBean.selectedRawMaterialPurchaseOrder.supplier.company}" >
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Amount to Pay:</td>
                                <td>
                                    <h:outputText value="#{rawMaterialPurchasingManagerBean.selectedRawMaterialPurchaseOrder.amountToPay}" >
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Status:</td>
                                <td>
                                    <h:outputText value="#{rawMaterialPurchasingManagerBean.selectedRawMaterialPurchaseOrder.status}" >
                                    </h:outputText>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel header="Material Requirement Plans" id="mrpPanel">
                        <p:dataTable id="mrPlans" var="mrplans" 
                                     value="#{rawMaterialPurchasingManagerBean.selectedRawMaterialPurchaseOrder.materialRequirementPlans}" 
                                     emptyMessage="No material requirement plans found with given criteria.">          
                            <p:column filterBy="#{mrplans.rawMaterial.name}" headerText="Raw Material Name" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.rawMaterial.name}" />  
                            </p:column> 
                            <p:column filterBy="#{mrplans.weight}" headerText="Required Amount (kg / litre)" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.weight}" />  
                            </p:column>
                            <p:column filterBy="#{mrplans.orderDate}" headerText="Date to Order" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.orderDate}" >
                                    <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>
                            </p:column>                        
                        </p:dataTable> 
                    </p:panel>
                    <p:panel id="addRMD" header="Add Delivery Record">
                        <p:messages />
                        
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">Raw Material:</td>
                                <td>
                                    <h:selectOneMenu id="selectOneRawMaterial" value="#{rawMaterialPurchasingManagerBean.rawMaterial.id}"
                                                     title="Raw material received.">
                                        <f:selectItem itemLabel="- Select Raw Material -" itemValue="" />
                                        <f:selectItems value="#{rawMaterialPurchasingManagerBean.rawMaterials}" var="rawMaterial" 
                                                       itemLabel="#{rawMaterial.name}" itemValue="#{rawMaterial.id}" />
                                    </h:selectOneMenu>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Amount Received (kg / litre):</td>
                                <td>
                                    <p:inputText id="amountReceived" label="Amount" required="true" 
                                                 requiredMessage="Amount received cannot be empty."
                                                 title="Amount of the raw material received."
                                                 value="#{rawMaterialPurchasingManagerBean.amountReceived}">
                                        <f:convertNumber type="number" />
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Delivery Number:</td>
                                <td>
                                    <p:inputText id="deliveryNumber" label="Delivery Number" required="true" 
                                                 requiredMessage="Delivery number cannot be empty."
                                                 title="Delivery number of the delivery."
                                                 value="#{rawMaterialPurchasingManagerBean.deliveryNumber}">
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td>Date Received:</td>
                                <td>
                                    <p:calendar required="true" requiredMessage="Received date is required." 
                                                value="#{rawMaterialPurchasingManagerBean.receivedDate}" pattern="dd-MM-yyyy" 
                                                title="Date of delivery."/> 
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <p:dataTable id="warehouseZones" var="warehouseZone" value="#{rawMaterialPurchasingManagerBean.warehouseZones}" 
                                                 selectionMode="single" 
                                                 selection="#{rawMaterialPurchasingManagerBean.selectedWarehouseZone}">
                                        <p:column filterBy="#{warehouseZone.zoneName}" headerText="Name" filterMatchMode="contains">  
                                            <h:outputText value="#{warehouseZone.zoneName}" />  
                                        </p:column> 
                                        <p:column filterBy="#{warehouseZone.type}" headerText="Type" filterMatchMode="contains">  
                                            <h:outputText value="#{warehouseZone.type}" />  
                                        </p:column> 
                                        <p:column filterBy="#{warehouseZone.quantityLimit}" headerText="Quantity Limit" filterMatchMode="contains">  
                                            <h:outputText value="#{warehouseZone.quantityLimit}" />  
                                        </p:column>
                                        <p:column filterBy="#{warehouseZone.currentQuantity}" headerText="Current Quantity" filterMatchMode="contains">  
                                            <h:outputText value="#{warehouseZone.currentQuantity}" />  
                                        </p:column> 
                                    </p:dataTable>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <p:commandButton id="btnRecordDelivery" value="Record Delivery"
                                                     ajax="true" update="addRMD"
                                                     title="Record the raw material delivery."
                                                     actionListener="#{rawMaterialPurchasingManagerBean.recordDelivery}"/>
                                    <p:commandButton id="btnDone" value="Done"
                                                     ajax="true" update="addRMD" immediate="true"
                                                     title="Done recording raw material deliveries."
                                                     actionListener="#{rawMaterialPurchasingManagerBean.back}"/>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel id="receivedRMD" header="Past Deliveries">
                        <p:dataTable id="receivedRMDs" var="rmd" value="#{rawMaterialPurchasingManagerBean.rawMaterialDeliveries}"
                                     emptyMessage="No past deliveries have been received.">
                            <p:column filterBy="#{rmd.deliveryNumber}" headerText="Delivery No." filterMatchMode="contains">  
                                <h:outputText value="#{rmd.deliveryNumber}" />  
                            </p:column> 
                            <p:column headerText="Received By">  
                                <h:outputText value="#{rmd.warehouseRep.name}" />  
                            </p:column> 
                            <p:column headerText="Supplier">  
                                <h:outputText value="#{rmd.supplier.company}" />  
                            </p:column> 
                            <p:column headerText="Storage Zone">  
                                <h:outputText value="#{rmd.warehouseZone.zoneName}" />  
                            </p:column>
                            <p:column headerText="Material Delivered" >  
                                <h:outputText value="#{rmd.materialRequired.rawMaterial.name}" />  
                            </p:column> 
                            <p:column headerText="Amount Delivered (kg / litre)" >  
                                <h:outputText value="#{rmd.materialRequired.weight}">
                                    <f:convertNumber type="number" />
                                </h:outputText>
                            </p:column> 
                        </p:dataTable>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
